import service from '@/request/index.js'

/* 首页 */

// 首页导航
export const getHomeNav = () => {
  return service.get('/homeNav.json')
}

// 首页商品列表（直播回放）
export const getHomeLiveList = (page) => {
  return service.get(`/video/item?page=${page}`)
}

// 商品详情（直播回放）
export const getLiveDetail = (itemId, actorId) => {
  return service.get(`/video/detail?itemId=${itemId}&actorId=${actorId}`)
}

/* 商城 */
// 商城导航
export const getShopNav = () => {
  return service.get('/shopNav.json')
}

// 商品列表（猜你喜欢）
export const getGuessYouLike = (page) => {
  return service.get(`/goods/personalized?page=${page}`)
}

// 商品详情
export const getGoodsDetail = (id) => {
  return service.get(`/goods/detail?itemId=${id}`)
}

/* 商城分类 */

//主分类
export const getMainCategory = () => {
  return service.get('/category.json')
}

// 子分类
// id 主分类id
export const getSubCategory = (id) => {
  return service.get(`/category/getSub?pid=${id}`)
}

// 商品列表（主分类商品列表）

// id 主分类id
// page 页码
// sort  new 新品、sell销量、pop综合
export const getCategoryGoodsList = (id, page, sort) => {
  return service.get(`/category/miniWall?fcid=${id}&page=${page}&sort=${sort}`)
}

/* 直播（正在直播） */

//直播分类
export const getLiveCategory = () => {
  return service.get('/live/tabHeader')
}

// 直播列表
export const getLiveList = (tabId, pageIndex) => {
  return service.get(`/live/tabList?tabId=${tabId}&pageIndex=${pageIndex}`)
}

/* 搜索 */

// 热门搜索
export const getHotSearch = () => {
  return service.get('/hotSearch.json')
}

// 根据关键词查找商品
// offset  30的倍数
export const getSearchGoods = (
  keyword,
  fcid,
  page = 1,
  sort = 'pop',
  minPrice,
  maxPrice,
  offset = 0,
) => {
  return service.get(
    `/search/searchByKeyword?q=${keyword}&fcid=${fcid}&page=${page}&sort=${sort}&minPrice=${minPrice}&maxPrice=${maxPrice}&offset=${offset}'`,
  )
}
